define(["jquery", "easy-admin"], function ($, ea) {
    function getQueryVariable(variable) {
        var query = window.location.search.substring(1);
        console.log(query)
        var vars = query.split("&");
        for (var i = 0; i < vars.length; i++) {
            var pair = vars[i].split("=");
            if (pair[0] == variable) {
                return decodeURI(pair[1]);  //处理中文显示异常
            }
        }
    }

    var init = {
        detail_url: 'mall.count/detail',
        table_elem: '#currentTable',
        table_render_id: 'currentTableRenderId',
        export_url: 'mall.count/export',
    };

    var Controller = {

        order: function () {
            ea.table.render({
                init: init,
                url: 'order',
                toolbar: ['refresh'],
                cols: [[
                    {field: 'user_id', title: '用户ID', search: false},
                    {field: 'user.name', title: '用户名'},
                    {field: 'user.mobile', title: '手机号'},
                    {field: 'order_num', title: '订单数量', search: false},
                    // {field: 'goods.title', title: '商品',},
                    // {
                    //     field: 'collage_status',
                    //     title: '订单状态',
                    //     selectList: {1: '拼团进行中', 2: '拼团成功', 3: '拼团失败'}
                    // },
                    {field: 'order_price', title: '订单金额', templet: ea.table.price, search: false},
                    // {field: 'create_time', minWidth: 80, title: '订单创建时间', search: 'range'},
                    {
                        field: 'pay_time_left',
                        minWidth: 80,
                        title: '创建开始时间',
                        search: 'rangeLeft',
                        hide: true,
                        searchOp: 'rangeLeft'
                    },
                    {
                        field: 'pay_time_right',
                        minWidth: 80,
                        title: '创建结束时间',
                        search: 'rangeRight',
                        hide: true,
                        searchOp: 'rangeRight'
                    },
                    {field: 'invite_num', minWidth: 80, title: '邀约人数', search: false},
                    {field: 'invite_price', minWidth: 80, title: '邀约金额', templet: ea.table.price, search: false},
                    // {field: 'collage.create_time', minWidth: 80, title: '拼团发起时间', search: 'range'},
                    {
                        title: '操作',
                        templet: ea.table.tool,
                        operat: [
                            [{
                                text: '拼团订单',
                                url: init.detail_url,
                                method: 'open',
                                auth: 'detail',
                                class: 'layui-btn layui-btn-normal layui-btn-xs',
                            }],
                        ]
                    }
                ]],
            });

            ea.listen();
        },
        detail: function () {
            ea.table.render({
                init: init,
                url:'detail',
                where: {id: getQueryVariable('id')},
                toolbar: ['refresh'],
                cols: [[
                    {field: 'order_no', title: '订单号', search: false},
                    {field: 'user.name', title: '用户名'},
                    {field: 'goods.title', title: '商品名',},
                    {
                        field: 'collage_status',
                        title: '订单状态',
                        selectList: {1: '拼团进行中', 2: '拼团成功', 3: '拼团失败', 4: '已退款'}
                    },
                    {field: 'order_price', title: '订单金额', templet: ea.table.price, search: false},
                    {field: 'create_time', minWidth: 80, title: '订单创建时间', search: false},
                    {
                        field: 'ea_mall_order-create_time_left',
                        minWidth: 80,
                        title: '创建开始时间',
                        search: 'rangeLeft',
                        hide: true,
                        searchOp: 'rangeLeft'
                    },
                    {
                        field: 'ea_mall_order-create_time_right',
                        minWidth: 80,
                        title: '创建结束时间',
                        search: 'rangeRight',
                        hide: true,
                        searchOp: 'rangeRight'
                    },
                    // {field: 'invite_num', minWidth: 80, title: '邀约人数', search: false},
                    // {field: 'invite_price', minWidth: 80, title: '邀约金额', templet: ea.table.price, search: false},
                    {field: 'collage.create_time', minWidth: 80, title: '拼团发起时间', search: false},
                ]],
            });
            ea.listen();
        },
    };
    return Controller;

});
